/*
 *
 *  This file is part of the SIRIUS library for analyzing MS and MS/MS data
 *  
 *  Copyright (C) 2013-2020 Kai Dührkop, Markus Fleischauer, Marcus Ludwig, Martin A. Hoffman and Sebastian Böcker, 
 *  Chair of Bioinformatics, Friedrich-Schilller University.
 *  
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 3 of the License, or (at your option) any later version.
 *  
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along with SIRIUS. If not, see <https://www.gnu.org/licenses/lgpl-3.0.txt>
 */

package de.unijena.bioinf.lcms.quality;

/**
 * Denotes that the instance does not align well with other instances
 */
public class AlignmentQuality implements QualityAnnotation {

    private static final AlignmentQuality NO_ALIGNMENT = new AlignmentQuality(0,0);

    public static AlignmentQuality none() {
        return NO_ALIGNMENT;
    }

    protected final int numberOfAlignedFeatures, medianNumberOfAlignedFeatures;

    public AlignmentQuality(int numberOfAlignedFeatures, int medianNumberOfAlignedFeatures) {
        this.numberOfAlignedFeatures = numberOfAlignedFeatures;
        this.medianNumberOfAlignedFeatures = medianNumberOfAlignedFeatures;
    }

    @Override
    public Quality getQuality() {
        if (numberOfAlignedFeatures < 10) {
            return Quality.UNUSABLE;
        }
        double pr = ((double)numberOfAlignedFeatures)/ medianNumberOfAlignedFeatures;
        if (pr < 0.1) return Quality.BAD;
        if (pr < 0.25) return Quality.DECENT;
        return Quality.GOOD;
    }

    @Override
    public String toString() {
        return "Alignment of " + numberOfAlignedFeatures + ", median is " + medianNumberOfAlignedFeatures;
    }
}
